#ifndef NOTIFICATION_H
#define NOTIFICATION_H

#ifdef __cplusplus
extern "C" {
#endif
#include "sqlite3.h"
#include "users.h"

extern struct users* g_users_list;
// 用户列表管理
void init_users_for_notification(const char* filename);
struct users* find_user_by_username(const char* username);
struct users* find_user_by_phone(const char* phone);
void cleanup_notification_system();

// 核心通知功能
int send_notification(const char *receiver, const char *sender, const char *type, const char *content);
int get_user_notifications(const char *username, int (*callback)(void*, int, char**, char**), void *user_data);
int get_unread_notification_count(const char *username);
int mark_notification_as_read(int notification_id);
int mark_all_notifications_as_read(const char *username);
int delete_notification(int notification_id);
int delete_all_user_notifications(const char *username);
int broadcast_notification(const char *type, const char *content);

// 包裹通知相关
int get_package_info(long package_id, char **recipient_phone, char **item_name);
char* find_username_by_phone(const char *phone_number);
int notify_package_status_change(long package_id, int new_status);
int notify_package_status_change_and_claim_code(long package_id, int new_status, const char *claim_code);
int send_coupon_notification(const char *username, double discount_rate, int count);

// 通知查询和过滤
int get_notifications_by_type(const char *username, const char *type, int (*callback)(void*, int, char**, char**), void *user_data);
int get_notification_types(int (*callback)(void*, int, char**, char**), void *user_data);
char** get_notification_type_list(int *count);
void free_notification_type_list(char **types, int count);

// 回调函数
int print_notification_callback(void *data, int argc, char **argv, char **azColName);
int print_notification_type_callback(void *data, int argc, char **argv, char **azColName);

// 管理员功能
int admin_send_announcement(const char *admin_username, const char *title, const char *content);

// 辅助函数
const char* get_user_type_name(int user_type);
char* build_notification_query(const char *username, const char *type);
#ifdef __cplusplus
}
#endif
#endif /* NOTIFICATION_H */
